OPC Studio User's Guide and Reference
Examples - Live Mapping - Define OPC UA type-less mapping and read

The example below shows how to define a new type-less mapping which maps a specified node in OPC Unified Architecture (OPC-UA) server to the Value member of your target MyClass2 object. The mapper is then instructed to invoke the OPC read operation, which will in turn store the OPC node’s value to your target object:

UAEndpointDescriptor endpointDescriptor =
    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
// or "https://opcua.demo-this.com:51212/UA/SampleServer/"

var mapper = new UAClientMapper();
var target = new MyClass2();

// Define a type-less mapping.

MemberInfo memberInfo = target.GetType().GetMember("Value").SingleOrDefault();
Debug.Assert(memberInfo != null);

mapper.DefineMapping(
    new UAClientDataMappingSource(
        endpointDescriptor,
        "nsu=http://test.org/UA/Data/ ;i=10389",
        UAAttributeId.Value,
        UAIndexRangeList.Empty,
        UAReadParameters.CacheMaximumAge),
    new UAClientDataMapping(typeof(Int32)),
    new ObjectMemberLinkingTarget(target.GetType(), target, memberInfo));

// Perform a read operation.
mapper.Read();

Public Shared Sub Main1()

    ' Define which server we will work with.
    Dim endpointDescriptor As UAEndpointDescriptor =
            "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
    ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
    ' or "https://opcua.demo-this.com:51212/UA/SampleServer/"

    Dim mapper = New UAClientMapper()
    Dim target = New MyClass2()

    ' Define a type-less mapping.

    Dim memberInfo = target.GetType().GetMember("Value").SingleOrDefault()
    Debug.Assert(memberInfo IsNot Nothing)

    mapper.DefineMapping( _
        New UAClientDataMappingSource( _
            endpointDescriptor, _
            "nsu=http://test.org/UA/Data/ ;i=10389", _
            UAAttributeId.Value, _
            UAIndexRangeList.Empty, _
            UAReadParameters.CacheMaximumAge), _
        New UAClientDataMapping(GetType(Int32)), _
        New ObjectMemberLinkingTarget(target.GetType(), target, memberInfo))

    ' Perform a read operation.
    mapper.Read()

    ' Display results
    Console.WriteLine(target.Value)
End Sub

 

See Also

Conceptual

Examples - OPC Unified Architecture